package com.uenpay.im.ui.old.activity.bankcard;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.uenpay.im.R;

import java.util.ArrayList;


/**
 * @author SL
 * @E-mail:
 * @date 创建时间：2016-7-11 下午12:22:56
 * @version 1.0
 * @parameter
 * @Function 银行卡列表适配器
 */
public class BankCardAdapter extends BaseAdapter {

	private Context mContext;
	private ArrayList<String> arrayList;
	private String selectedBankCard;

	public BankCardAdapter(Context _Context, String _SelectedBankCard,
			ArrayList<String> _ArrayList) {
		mContext = _Context;
		arrayList = _ArrayList;
		selectedBankCard = _SelectedBankCard;
	}

	public void setSelectedBankCard(String bankCard) {
		selectedBankCard = bankCard;
		notifyDataSetChanged();
	}

	@Override
	public int getCount() {
		return arrayList == null ? 0 : arrayList.size();
	}

	@Override
	public Object getItem(int arg0) {
		return arrayList == null ? null : arrayList.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		BankCardViewHolder holder = null;
		if (arg1 == null) {
			arg1 = View.inflate(mContext, R.layout.item_bank_card_list_layout,
					null);
			holder = new BankCardViewHolder();
			holder.bankCardName = (TextView) arg1
					.findViewById(R.id.bank_card_type_name);
			holder.checkIv = (ImageView) arg1.findViewById(R.id.check_iv);
			arg1.setTag(holder);
		} else {
			holder = (BankCardViewHolder) arg1.getTag();
		}
		if (selectedBankCard.equals(arrayList.get(arg0))) {
			holder.checkIv.setVisibility(View.VISIBLE);
		} else {
			holder.checkIv.setVisibility(View.GONE);
		}
		holder.bankCardName.setText(arrayList.get(arg0));
		return arg1;
	}

	public class BankCardViewHolder {
		private TextView bankCardName;
		private ImageView checkIv;
	}
}
